<template>
    <div>
        <mt-field label="用户名" type="text" placeholder="请输入用户名" v-model="uname" ></mt-field>
        <mt-field label="密码" type="password" placeholder="请输入用户名" v-model="upwd"></mt-field>
        <mt-button type="primary" size="large" @click.native="login">登录</mt-button>
    </div>
</template>

<script>
export default {
    data(){
        return {
            uname:"",
            upwd:""
        }
    },
    methods:{
        login(){
            if(this.uname == ""){
                this.$toast({
                    message:"请输入用户名",
                    duration:1000
                })
            }else if(this.upwd == ""){
                this.$toast({
                    message:"请输入密码",
                    duration:1000
                })
            }else{
                var reg = /^[0-9a-zA-z]\w{2,11}$/i;
                if(reg.test(this.uname)){
                    this.axios.get("login",{
                        params:{
                            uname:this.uname,
                            upwd:this.upwd
                        }
                    }).then(result => {
                        if(result.data.node == 1){
                            this.$toast({
                                message:"登录成功",
                                duration:1000
                            });
                            this.$router.push("/home")
                        }else{
                            this.$toast({
                                message:"用户名或密码错误",
                                duration:1000
                            })
                        }
                    })
                }else{
                    this.$toast({
                        message:"请输入合法用户名",
                        duration:1500
                    });
                }
            }
        }
    }
}
</script>

<style>

</style>